package cn.itsource.ymcc.web.controller;


import cn.itsource.result.JSONResult;
import cn.itsource.result.PageList;
import cn.itsource.ymcc.doc.CourseDoc;
import cn.itsource.ymcc.dto.CourseEsSearchDto;
import cn.itsource.ymcc.service.IEsCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/course")
public class EsCourseController {
    @Autowired
    private IEsCourseService esCourseService;

    @PostMapping("/save")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        esCourseService.saveCourse(doc);
        return JSONResult.success();
    }

    @PostMapping("/delete")
    public JSONResult deleteCourse(@RequestBody Long id){
        esCourseService.deleteCourse(id);
        return JSONResult.success();
    }

    @PostMapping("/search")
    public JSONResult searchCourse(@RequestBody CourseEsSearchDto courseEsSearchDto){
        PageList<CourseDoc> pageList = esCourseService.searchCourse(courseEsSearchDto);
        return JSONResult.success(pageList);
    }
}
